/**
 * Created by dale on 2017/8/2.
 */
var currentDepId;
var staffList;
var currentDepName;
var checkId;
$(document).ready(function (){
    var  depList= $('#depList');
    staffList=$('#staffList');
    $('.xh-datagrid-toolbar').parseToolbar();

    staffList.initDataGrid(moduleUrl + 'staff/getStaffData')
        .setSelectThenEnable(['bt_list_del','bt_list_move','bt_list_group','bt_list_viewHistory','bt_list_transfer'], ['bt_list_addStaffNumber','bt_list_set_power', 'bt_list_view_power', 'bt_list_account','bt_list_info','bt_list_setCharge']);
    $('#bt_list_add').setButtonDisable('eu');
    $('#bt_list_import').setButtonDisable('eu');



    xhTool.bindDocKeyDown($('#bt_list_search'));
    var $btn_menu1=$('#bt_list_wstatus').menubutton({
            iconCls: 'fa fa-user',
            menu: '#mm',
    });
    var $btn_menu2=$('#bt_list_sstatus').menubutton({
        iconCls: 'fa fa-user',
        menu: '#mm1',
    });
    var $btn_menu3=$('#bt_list_ostatus').menubutton({
        iconCls: 'fa fa-user',
        menu: '#mm2',
    });
    if ($('#bt_list_add_menu').length > 0) {
        var $btn_menu5=$('#bt_list_add_menu').menubutton({
            iconCls: 'fa fa-plus',
            menu: '#addStaffMenu'
        });
        $($btn_menu5.menubutton('options').menu).menu({
            onClick: function (item) {
                //item 的相关属性参见API中的menu
                var name = item.text;
                var type = '';
                if (name == '新增在职职工') {
                    type = 'office';
                } else if (name == '新增离职职工') {
                    type = 'leave';
                } else if (name == '新增特殊职工') {
                    type = 'special';
                }
                window.top.xhTop.showModal({
                    title: name,
                    content: '<iframe src="'+moduleUrl+'staff_info/addStaffForm?type='+type+'"  style="width: 100%;;border-style: none;padding: 0px;height: 420px"  scrolling="yes"   ></iframe>',
                    button:'提交',
                    width:900,
                    backClose: false
                });
            }
        })

    }
    if ($('#bt_list_import_menu').length > 0) {
        var $btn_menu4=$('#bt_list_import_menu').menubutton({
            iconCls: 'fa fa-plus',
            menu: '#importMenu'
        });
        $($btn_menu4.menubutton('options').menu).menu({
            onClick: function (item) {
                //item 的相关属性参见API中的menu
                var name = item.text;
                // console.log(name);
                if (name == '在职导入') {
                    window.top.swal({
                        title: '导入在职职工信息',
                        showCancelButton: true,
                        cancelButtonText: '取消',
                        showLoaderOnConfirm: true,
                        allowOutsideClick: true,
                        input: 'file',
                        inputAttributes: {accept: '.xls,.xlsx'},
                        confirmButtonText: '导入',
                        preConfirm: function(file) {
                            return new Promise(function (resolve, reject) {
                                if (!file) {
                                    reject('文件不能为空！');
                                } else {
                                    var fileData = new FormData();
                                    fileData.append('file', file);
                                    $.ajax({
                                        url: baseUrl + 'hrm/staff_info/importStaff',
                                        type: 'POST',
                                        processData: false,
                                        contentType: false,
                                        data: fileData,
                                        complete: function(XMLHttpRequest){
                                            var result = XMLHttpRequest.responseJSON;
                                            console.log(result);
                                            if(xhExtra.checkError(result)) return false;
                                            window.top.xhTop.showSuccess(result.msg);
                                        }
                                    });
                                }
                            })
                        }
                    });
                } else if (name == '离职导入') {
                    window.top.swal({
                        title: '导入离职职工信息',
                        showCancelButton: true,
                        cancelButtonText: '取消',
                        showLoaderOnConfirm: true,
                        allowOutsideClick: true,
                        input: 'file',
                        inputAttributes: {accept: '.xls,.xlsx'},
                        confirmButtonText: '导入',
                        preConfirm: function(file) {
                            return new Promise(function (resolve, reject) {
                                if (!file) {
                                    reject('文件不能为空！');
                                } else {
                                    var fileData = new FormData();
                                    fileData.append('file', file);
                                    $.ajax({
                                        url: baseUrl + 'hrm/staff_info/importLeaveStaff',
                                        type: 'POST',
                                        processData: false,
                                        contentType: false,
                                        data: fileData,
                                        complete: function(XMLHttpRequest){
                                            var result = XMLHttpRequest.responseJSON;
                                            if(xhExtra.checkError(result)) return false;
                                            window.top.xhTop.showSuccess(result.msg);
                                        }
                                    });
                                }
                            })
                        }
                    });
                }

                // if(item.text =='兼职'){
                //     status=1;
                // }else if(item.text=='实习'){
                //     status=2;
                // }else if(item.text=='全职'){
                //     status=3;
                // }
            }
        })

    }

    if ($('#bt_list_special').length > 0) {
        var $btn_spcial_menu=$('#bt_list_special').menubutton({
            iconCls: 'fa fa-user',
            menu: '#specialMenu'
        });
        $($btn_spcial_menu.menubutton('options').menu).menu({
            onClick: function (item) {
                //item 的相关属性参见API中的menu
                var name = item.text;
                var type = 'bSpecial';
                var status = 0;
                if (name == '设置为特殊') {
                    status = 2;
                } else if (name = '恢复正常') {
                    status = 1;
                }
                var ids = staffList.getDataGridSelectedFields('iStaffId');
                xhExtra.ajaxRequest('hrm/staff_info/changeStatus', {ids:ids,status:status,type:type}, {}, function (res) {
                    window.top.xhTop.showSuccess(res.msg);
                    staffList.addDataGridParams(getParams()).datagrid('getPanel').panel('setTitle', '职工列表（' + currentDepName + '）');
                });

            }
        })

    }



    $($btn_menu1.menubutton('options').menu).menu({
        onClick: function (item) {
            //item 的相关属性参见API中的menu
            var status=0;
            var type='iWorkStatus';
            if(item.text=='兼职'){
                status=1;
            }else if(item.text=='实习'){
                status=2;
            }else if(item.text=='全职'){
                status=3;
            } else if (item.text == '应届') {
                status=4;
            }
            var ids = staffList.getDataGridSelectedFields('iStaffId');
            xhExtra.ajaxRequest('hrm/staff_info/changeStatus', {ids:ids,status:status,type:type}, {}, function (res) {
                window.top.xhTop.showSuccess(res.msg);
                staffList.addDataGridParams(getParams()).datagrid('getPanel').panel('setTitle', '职工列表（' + currentDepName + '）');
            });
            // $.ajax({
            //     url:moduleUrl+'staff/changeStatus',
            //     data:{ids:ids,status:status,type:type},
            //     type:'POST',
            //     success:function (data) {
            //         staffList.addDataGridParams(getParams()).datagrid('getPanel').panel('setTitle', '职工列表（' + currentDepName + '）');
            //     },
            //     error:function (data) {
            //         console.log(data);
            //     }
            // });
        }
    })
    $($btn_menu2.menubutton('options').menu).menu({
        onClick: function (item) {
            //item 的相关属性参见API中的menu
            var status=0;
            var type='iStaffStatus';
            var html = '<input type="date" class="form-control" id="dateInput" >';
            if(item.text=='在职'){
                status=1;
            }else if(item.text=='离职'){
                status=2;
                html += '<br><input type="text" class="form-control" id="leaveReason" >';
            }else if(item.text=='退休'){
                status=3;
            }
            var ids = staffList.getDataGridSelectedFields('iStaffId');
            window.top.swal({
                titleText: '选择时间',
                html:html,
                showCancelButton: true,
                cancelButtonText: '取消',
                confirmButtonText: '确认',
                showLoaderOnConfirm: true,
                preConfirm: function () {
                    return new Promise(function (resolve, reject) {
                        var date = $('#dateInput' , window.top.document).val();
                        if (!date) {
                            reject('时间必填！');
                        } else {
                            resolve(date);
                        }
                    })
                },
                allowOutsideClick: true
            }).then(function (date) {
                var params = {ids:ids,status:status,type:type,date:date};
                if ($('#leaveReason', window.top.document).length > 0 ) {
                    var sLeaveReason = $('#leaveReason', window.top.document).val();
                    if (sLeaveReason) {
                        params.sLeaveReason = sLeaveReason;
                    }
                }
                xhExtra.ajaxRequest('hrm/staff_info/changeStatus', params, {}, function (res) {
                    window.top.xhTop.showSuccess(res.msg);
                    staffList.addDataGridParams(getParams()).datagrid('getPanel').panel('setTitle', '职工列表（' + currentDepName + '）');
                });
            }, function(dismiss) {});


        }
    });
    $($btn_menu3.menubutton('options').menu).menu({
        onClick: function (item) {
            //item 的相关属性参见API中的menu
            var status=0;
            var type='iOfferStatus';
            if(item.text=='试用'){
                status=1;
            }else if(item.text=='正式') {
                status = 2;
            } else if (item.text == '非正式') {
                status = 3;
            } else if (item.text == '其他') {
                status = 4;
            }
            var ids = staffList.getDataGridSelectedFields('iStaffId');
            xhExtra.ajaxRequest('hrm/staff_info/changeStatus', {ids:ids,status:status,type:type}, {}, function (res) {
                window.top.xhTop.showSuccess(res.msg);
                staffList.addDataGridParams(getParams()).datagrid('getPanel').panel('setTitle', '职工列表（' + currentDepName + '）');
            });
            // $.ajax({
            //     url:moduleUrl+'staff/changeStatus',
            //     data:{ids:ids,status:status,type:type},
            //     type:'POST',
            //     success:function (data) {
            //         staffList.addDataGridParams(getParams()).datagrid('getPanel').panel('setTitle', '职工列表（' + currentDepName + '）');
            //     },
            //     error:function (data) {
            //         console.log(data);
            //     }
            // });
        }
    });
        
    $('#bt_list_transfer').click(function () {
        if(xhExtra.buttonDisabled($(this))){
            return false;
        }
        var staffId = staffList.getDataGridSelectedField('iStaffId');
        window.top.xhTop.showModal({
            title:'岗位调动',
            content: '<iframe src="'+moduleUrl+'mine/transferForm?staffId='+staffId+'"  style="width: 100%;;border-style: none;padding: 0px;height: 320px"  scrolling="yes"   ></iframe>',
            button:'提交',
            width: '930',
            backClose: false
        });
    });



    $('#cc').resizable({    //左侧拖曳
        onStopResize:function (e) {
            depList.treegrid('resize',{width:e['data']['width']});
            $('.xh-datagrid').attr('width',($(document).width()-e['data']['width']));
            staffList.datagrid('resize',{width:($(document).width()-e['data']['width'])})
        },
        onResize:function (e) {
            depList.treegrid('resize',{width:e['data']['width']}+'px');
            staffList.datagrid('resize',{width:($(document).width()-e['data']['width'])})
        }
    });



    depList.treegrid({
        selectOnCheck:false,
        checkOnSelect:false,
        onSelect:function (row) {
            currentDepId=row['iDepId'];
            currentDepName=row['sDepName'];
            depList.treegrid('expand',currentDepId);
            $('#bt_list_add').setButtonEnable('eu');
            $('#bt_list_import').setButtonEnable('eu');
            staffList.addDataGridParams(getParams()).datagrid('getPanel').panel('setTitle', '职工列表（' + row['sDepName'] + '）');
        },
        onBeforeCheck:function (row) {
            if(checkId==undefined){
                checkId = row['iDepId'];
                return true;
            }else {
                if(checkId==row['iDepId']){
                    depList.treegrid('uncheckRow',row['iDepId']);
                    return false;
                }else {
                    depList.treegrid('uncheckRow',checkId);
                }
            }
        },
        onCheck:function (row) {
            checkId = row['iDepId'];
        },
        onLoadSuccess:function (row, data) {
            depList.treegrid('select',0);
        }

    });

    DataGrid.onLoadSuccess = function(data){
        staffList.dataGridClear();
    };


    $('#bt_list_del').click(function () {
        if(xhExtra.buttonDisabled($(this))){
            return false;
        }
        var ids = staffList.getDataGridSelectedFields('iStaffId');
        $.overtFun.clickDelList(ids, moduleUrl + 'staff/delStaff',staffList);
    });

    $('#bt_list_search').click(function () {
        var params = getParams();
        staffList.addDataGridParams(params);
    });

    // $('#bt_list_import').click(function () {
    //     window.top.swal({
    //         title: '导入职工信息',
    //         showCancelButton: true,
    //         cancelButtonText: '取消',
    //         showLoaderOnConfirm: true,
    //         allowOutsideClick: true,
    //         input: 'file',
    //         inputAttributes: {accept: '.xls,.xlsx'},
    //         confirmButtonText: '导入',
    //         preConfirm: function(file) {
    //             return new Promise(function (resolve, reject) {
    //                 if (!file) {
    //                     reject('文件不能为空！');
    //                 } else {
    //                     var fileData = new FormData();
    //                     fileData.append('file', file);
    //                     $.ajax({
    //                         url: baseUrl + 'hrm/staff_info/importStaff',
    //                         type: 'POST',
    //                         processData: false,
    //                         contentType: false,
    //                         data: fileData,
    //                         complete: function(XMLHttpRequest){
    //                             var result = XMLHttpRequest.responseJSON;
    //                             console.log(result);
    //                             if(xhExtra.checkError(result)) return false;
    //                             window.top.xhTop.showSuccess('导入成功');
    //                         }
    //                     });
    //                 }
    //             })
    //         }
    //     });
    // });
    $('#bt_list_export_staff').click(function () {
        var key=xhExtra.getValue($('#list_search'));
        var all=xhExtra.getValue($('#select_all'));
        var workstate=xhExtra.getValue($('#select_work'));
        var staffstate=xhExtra.getValue($('#select_staff'));
        var offerstate=xhExtra.getValue($('#select_offer'));
        window.open(moduleUrl+'staff/exportStaff?key='+key+'&all='+all+'&depId='+currentDepId+'&workstate='+workstate+'&staffstate='+staffstate+'&offerstate='+offerstate);
    });

    $('#bt_list_info').click(function () {
        if(xhExtra.buttonDisabled($(this))){
            return false;
        }
        var id=staffList.getDataGridSelectedField('iStaffId');
        window.top.xhTop.createNewTab('员工详情',moduleUrl+'staff/staffInfo?id='+id,true);
    });

    $('#bt_list_move').click(function () {
        if(xhExtra.buttonDisabled($(this))){
            return false;
        }
        var $depArray=depList.treegrid('getChecked');
        if($depArray.length>0){
            var depId=$depArray[0]['iDepId'];
            var depName=$depArray[0]['sDepName'];
            var staffIds=staffList.getDataGridSelectedFields('iStaffId');
            var staffName=staffList.getDataGridSelectedFields('sStaffName');
            window.top.swal({
                title: '添加人员到部门',
                text: '你确定要将'+staffName+'移动到'+depName+"部门",
                type: 'warning',
                showCancelButton: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(function() {
                $.ajax({
                    url:moduleUrl+'staff/moveGroup',
                    data:{depId:depId,staffIds:staffIds},
                    type:'post',
                    success:function (data) {
                        var params = getParams();
                        params.depId = depId;
                        staffList.addDataGridParams(params);
                        staffList.datagrid('getPanel').panel('setTitle', '职工列表（' + $depArray[0]['sDepName'] + '）');
                        staffList.dataGridClear();
                        window.top.swal(
                            '添加成功',
                            ''+staffName+'已成功添加到'+depName+"部门",
                            'success'
                        )
                    },
                    error:function (data) {
                        console.log(data);
                        window.top.swal(
                            '失败',
                            data['responseText'],
                            'error'
                        );
                    }

                })

            }, function(dismiss) {
                // dismiss can be 'overlay', 'cancel', 'close', 'esc', 'timer'
                if (dismiss === 'cancel') {
                    window.top.swal(
                        '取消',
                        '取消添加',
                        'error'
                    )
                }
            });
        }else {
            alert('请选择部门');
        }
    });


    DataGrid.onDblClickRow=function (rowIndex, rowData) {
        // var id=rowData['iStaffId'];
        // var url='iDepId='+currentDepId+'&sDepName='+escape(currentDepName);
        // window.top.xhTop.showModal({
        //     title:'编辑职工',
        //     content: '<iframe src="'+moduleUrl+'staff/editForm/'+id+'?'+url+'"  style="width: 100%;;border-style: none;padding: 0px;height: 420px"  scrolling="yes"   ></iframe>',
        //     button:'提交',
        //     size: 'lg',
        //     backClose: false,
        // });
        $('#title').contents()[0]['data'] = rowData['sStaffName'];
        window.frames['tabFrame'].location.href = baseUrl+'hrm/staff_info/staffTab?staffId='+rowData['iStaffId'];
        $('#titleRow').show();
        $('#tabRow').show();
        xhExtra.forwardToForm(true);
    };
    // DataGrid.onLoadSuccess = function(data){
    //     console.log('aaa');
    //     staffList.dataGridClear();
    // };


    $('#bt_list_add').click(function () {
        if(xhExtra.buttonDisabled($(this))){
            return false;
        }
        var url='iDepId='+currentDepId+'&sDepName='+escape(currentDepName);
        window.top.xhTop.showModal({
            title:'新增职工',
            content: '<iframe src="'+moduleUrl+'staff/addForm?'+url+'"  style="width: 100%;;border-style: none;padding: 0px;height: 420px"  scrolling="yes"   ></iframe>',
            button:'提交',
            size: 'lg',
            backClose: false,
        });

    });

    $('#bt_list_setCharge').click(function () {
        if(xhExtra.buttonDisabled($(this))){
            return false;
        }
        var staffId = staffList.getDataGridSelectedField('iStaffId');
        var staffName =staffList.getDataGridSelectedField('sStaffName');
        var url='staffId='+staffId+'&staffName='+escape(staffName);
        window.top.xhTop.showModal({
            title:'设置负责人',
            content: '<iframe src="'+moduleUrl+'staff/setCharge?'+url+'"  style="width: 100%;;border-style: none;padding: 0px;height: 220px"  scrolling="yes"   ></iframe>',
            button:'提交',
            backClose: false,
        });
    });

    //设置权限
    $('#bt_list_set_power').click(function () {
        if(xhExtra.buttonDisabled($(this))) return false;
        var userId = staffList.getDataGridSelectedField('iUserId');
        if (!userId) {
            window.top.swal('用户id不存在！', '', 'error');
            return false;
        }
        window.top.xhTop.createNewTab('设置权限', baseUrl + 'User/userSetPower?iUserId=' + userId, true);
    });

    //查看权限
    $('#bt_list_view_power').click(function () {
        if(xhExtra.buttonDisabled($(this))) return false;
        var userId = staffList.getDataGridSelectedField('iUserId');
        if (!userId) {
            window.top.swal('用户id不存在！', '', 'error');
            return false;
        }
        window.top.xhTop.createNewTab('查看权限', baseUrl + 'User/userSetPower/true?iUserId=' + userId, true);
    });

    //处理账号
    $('#bt_list_account').click(function () {
        if(xhExtra.buttonDisabled($(this))) return false;
        var staffId   = staffList.getDataGridSelectedField('iStaffId'),
            phoneNum  = staffList.getDataGridSelectedField('sSelfPhone'),
            staffName = staffList.getDataGridSelectedField('sStaffName');
        window.top.xhTop.showModal({
            title: '账号管理-' + staffName,
            content: xhTool.getFrameString('hrm/Staff/staffAccount', {staffId: staffId,sName:escape(staffName),sPhoneNum:phoneNum}, 500),
            size: 'lg',
            button:'创建账号'
        });
    });

    //设置角色
    $('#bt_list_group').click(function() {
        if(xhExtra.buttonDisabled($(this))) return false;
        var userIds = xhTool.clearNullArr(staffList.getDataGridSelectedFields('iUserId', true));
        if (!userIds) {
            window.top.xhTop.showError('选中人员中无用户id！');
            return false;
        }
        window.top.xhTop.showModal({
            title: '设置角色(共' + userIds.length + '人)',
            button: '确认',
            content: xhTool.getFrameString('Group/userGroup', {type: 2, userIds: userIds.join(',')}, 500)
        });
    });

    $('#tabReturn').click(function () {
        $('#titleRow').hide();
        $('#tabRow').hide();
        staffList.dataGridReload();
        xhExtra.backToList();
    });

    //查看操作历史
    $('#bt_list_viewHistory').click(function () {
        if(xhExtra.buttonDisabled($(this))){
            return false;
        }
        var id = staffList.getDataGridSelectedField('iStaffId');
        if(!id){
            window.top.xhTop.showError('错误','请选择一个查看的人');
            return false;
        }
        window.top.xhTop.showModal({
            title:'查看操作历史',
            content: '<iframe src="'+moduleUrl+'staff/staffHisDetail?staffId='+id+'"  style="width: 100%;;border-style: none;padding: 0px;height: 320px"  scrolling="yes"   ></iframe>',
            // size:'lg',
            backClose: false
        });
    });
    
    $('#bt_list_seeEmail').click(function () {
        window.top.xhTop.createNewTab('百分邮箱列表',baseUrl+'hrm/staff_info/hundredMailList');
    });
    //导出职工工号
    $('#bt_list_export_staffNumber').click(function () {
        xhExtra.ajaxRequest('hrm/staff_info/ajaxGetFlowDep',{},{},function (res) {
            var html = '';
            html = '<select id="depIds" class="form-control" multiple="multiple">\n' ;
            if (res) {
                $.each(res, function (id,text) {
                    html += '      <option value="'+id+'" ';
                    html +='>'+text+'</option>\n' ;
                });
            }
            html +='      </select>';
            console.log(html);
            swal({
                showCancelButton: true,
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                showLoaderOnConfirm: true,
                allowOutsideClick: false,
                title: '选择几个部门',
                html: html,
                preConfirm: function() {
                    return new Promise(function (resolve, reject) {
                        var depIds = $('#depIds').val();
                        if(!depIds){
                            reject('说明不能为空！');
                        }
                        else {
                            resolve(depIds)
                        }
                    })
                },
                onOpen:function () {
                    $('#depIds').select2();

                }
            }).then(function (depIds) {
                var depIds = depIds.join(',');
                window.open(baseUrl+'hrm/staff_info/exportStaffForNumber?depIds='+depIds);
            },function (dismiss) {
                return false;
            });
        });

    });
    
    $('#bt_list_importStaffNumber').click(function () {
        window.top.swal({
            title: '导入excel文件',
            showCancelButton: true,
            cancelButtonText: '取消',
            showLoaderOnConfirm: true,
            allowOutsideClick: true,
            input: 'file',
            inputAttributes: {accept: '.xls,.xlsx'},
            confirmButtonText: '导入',
            preConfirm: function(file) {
                return new Promise(function (resolve, reject) {
                    if (!file) {
                        reject('文件不能为空！');
                    } else {
                        var fileData = new FormData();
                        fileData.append('file', file);
                        $.ajax({
                            url: baseUrl + 'hrm/staff_info/importStaffNumber',
                            type: 'POST',
                            processData: false,
                            contentType: false,
                            data: fileData,
                            complete: function(XMLHttpRequest){
                                var result = XMLHttpRequest.responseJSON;
                                if(xhExtra.checkError(result)) return false;
                                if (result.code == 200) {
                                    if (result.data.length > 0) {
                                        window.top.xhTop.showSuccess(result.msg);
                                        var str =' <a id="bt_view_exportUndo"   download="未处理工号名单.xls" href="#"  class="btn btn-success btn-md" onclick="return ExcellentExport.excel(this, \'datatable\', \'xh\');" style="margin-left: 15px;margin-bottom:10px;width: 80px;">导出</a>';
                                        str += '<table id="datatable" class="table table-hover">' +
                                            '           <tr>' +
                                            '               <th>名称</th>' +
                                            '               <th>工号</th>' +
                                            '           </tr>' ;
                                        $.each(result.data, function (i,item) {
                                            str += '        <tr>' ;
                                            str += '            <td>'+item['sStaffName']+'</td>' +
                                                '               <td>'+item['sStaffNumber']+'</td>' +
                                                '           </tr>' ;
                                        });
                                        str +='</table>';
                                        swal({
                                            showConfirmButton: false,
                                            allowOutsideClick: true,
                                            title: '未处理工号列表',
                                            html : str
                                            // confirmButtonText: '导出',
                                            // buttons:{
                                            //
                                            // },
                                            // onOpen:function () {
                                            //     $('.swal2-confirm').attr('download', '未处理工号名单.xls');
                                            //     $('.swal2-confirm').attr('href', '#');
                                            //     $('.swal2-confirm').attr('onclick', 'return ExcellentExport.excel(this, \'datatable\', \'xh\');');
                                            // }
                                        }).then(function (confirm) {
                                            // return ExcellentExport.excel(this, 'datatable', 'xh');
                                        },function (dismiss) {
                                            return false;
                                        });
                                    } else {
                                        window.top.xhTop.showSuccess(result.msg);
                                    }
                                    staffList.dataGridReload();
                                }
                            }
                        });
                    }
                })
            }
        });
    });

    $('#bt_list_addStaffNumber').click(function () {
        if (xhExtra.buttonDisabled($(this))) {
            return false;
        }
        var staffId = staffList.getDataGridSelectedField('iStaffId');
        var staffNumber = staffList.getDataGridSelectedField('sStaffNumber');
        if (staffNumber) {
            window.top.xhTop.showError('错误', '工号已经存在,无法编辑');
            return false;
        }
        window.top.swal({
            title: '输入工号',
            showCancelButton: true,
            cancelButtonText: '取消',
            showLoaderOnConfirm: true,
            allowOutsideClick: true,
            input: 'text',
            preConfirm: function(staffNumber) {
                return new Promise(function (resolve, reject) {
                    if(!staffNumber){
                        resolve('工号不能为空！');
                    } else {
                        resolve(staffNumber);
                    }
                })
            }
        }).then(function (staffNumber) {
            xhExtra.ajaxRequest('hrm/staff_info/addStaffNumber',{staffNumber:staffNumber,staffId:staffId},{},function (result) {
                window.top.xhTop.showSuccess(result.msg);
                staffList.dataGridReload();
            });
        },function (dismiss) {
            return false;
        })
    })

});

function getParams() {
    var key=xhExtra.getValue($('#list_search'));
    var all=xhExtra.getValue($('#select_all'));
    var workstate=xhExtra.getValue($('#select_work'));
    var staffstate=xhExtra.getValue($('#select_staff'));
    var offerstate=xhExtra.getValue($('#select_offer'));
    var special =xhExtra.getValue($('#select_special'));
    return {key:key,all:all,workstate:workstate,staffstate:staffstate,offerstate:offerstate,depId:currentDepId,special:special};
}